﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Telerik.Windows.Controls.GridView;
using Telerik.Windows;

namespace Kaesoft.Hospedaje.Common
{
    public partial class VentanaBuscarCatalogosView : ChildWindow
    {
        VentanaBuscarCatalogosViewModel viewModel;

        public VentanaBuscarCatalogosView()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(BuscarCatalogoView_Loaded);

            radGridView.AddHandler(GridViewCellBase.CellDoubleClickEvent, new EventHandler<RadRoutedEventArgs>(OnCellDoubleClickEvent), false);
        }

        void BuscarCatalogoView_Loaded(object sender, RoutedEventArgs e)
        {
            viewModel = (this.DataContext as VentanaBuscarCatalogosViewModel);
            viewModel.ResetPager += (s, ev) =>
            {
                PagerCatalogos.PageIndex = 0;
            };
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void OnCellDoubleClickEvent(object sender, RadRoutedEventArgs args)
        {
            viewModel.SeleccionarCatalogo(null);
        }

        private void PagerCatalogos_PageIndexChanged(object sender, Telerik.Windows.Controls.PageIndexChangedEventArgs e)
        {
            if (viewModel == null) return;
            viewModel.BuscarCatalogo(PagerCatalogos.PageIndex);
        }

        private void txtCriterio_KeyUp(object sender, KeyEventArgs e)
        {
            if (viewModel == null) return;
            if (e.Key == Key.Enter) viewModel.BuscarCatalogo(0);
        }
    }
}

